package com.restaurant.controller.mini;

import com.restaurant.common.result.Result;
import com.restaurant.entity.Category;
import com.restaurant.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 小程序分类控制器
 */
@RestController
@RequestMapping("/mini/category")
@Slf4j
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 获取分类列表
     */
    @PostMapping("/list")
    public Result<List<Category>> list() {
        log.info("获取分类列表");
        
        List<Category> categories = categoryService.lambdaQuery()
                .orderByAsc(Category::getSort)
                .list();
        
        return Result.success(categories);
    }

    /**
     * 根据类型获取分类
     */
    @PostMapping("/listByType")
    public Result<List<Category>> listByType(@RequestParam Integer type) {
        log.info("根据类型获取分类：{}", type);
        
        List<Category> categories = categoryService.lambdaQuery()
                .eq(Category::getType, type)
                .orderByAsc(Category::getSort)
                .list();
        
        return Result.success(categories);
    }
}